{{#description}}/// {{{.}}}{{/description}}
class {{{enumName}}} {
  /// Instantiate a new enum with the provided [value].
  const {{{enumName}}}._(this.value);

  /// The underlying value of this enum member.
  final {{{dataType}}} value;

  @override
  String toString() => value{{^isString}}.toString(){{/isString}};

  {{{dataType}}} toJson() => value;

  {{#allowableValues}}
    {{#enumVars}}
  static const {{{name}}} = {{{enumName}}}._({{#isString}}r{{/isString}}{{{value}}});
    {{/enumVars}}
  {{/allowableValues}}

  /// List of all possible values in this [enum][{{{enumName}}}].
  static const values = <{{{enumName}}}>[
  {{#allowableValues}}
    {{#enumVars}}
    {{{name}}},
    {{/enumVars}}
  {{/allowableValues}}
  ];

  static {{{enumName}}} fromJson(dynamic value) =>
    {{{enumName}}}TypeTransformer().decode(value);

  static List<{{{enumName}}}> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
    json == null || json.isEmpty
      ? true == emptyIsNull ? null : <{{{enumName}}}>[]
      : json
          .map((value) => {{{enumName}}}.fromJson(value))
          .toList(growable: true == growable);
}

/// Transformation class that can [encode] an instance of [{{{enumName}}}] to {{{dataType}}},
/// and [decode] dynamic data back to [{{{enumName}}}].
class {{{enumName}}}TypeTransformer {
  const {{{enumName}}}TypeTransformer._();

  factory {{{enumName}}}TypeTransformer() => _instance ??= {{{enumName}}}TypeTransformer._();

  {{{dataType}}} encode({{{enumName}}} data) => data.value;

  /// Decodes a [dynamic value][data] to a {{{enumName}}}.
  ///
  /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
  /// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
  /// cannot be decoded successfully, then an [UnimplementedError] is thrown.
  ///
  /// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
  /// and users are still using an old app with the old code.
  {{{enumName}}} decode(dynamic data, {bool allowNull}) {
    switch (data) {
      {{#allowableValues}}
        {{#enumVars}}
      case {{#isString}}r{{/isString}}{{{value}}}: return {{{enumName}}}.{{{name}}};
        {{/enumVars}}
      {{/allowableValues}}
      default:
        if (allowNull == false) {
          throw ArgumentError('Unknown enum value to decode: $data');
        }
    }
    return null;
  }

  /// Singleton [{{{enumName}}}TypeTransformer] instance.
  static {{{enumName}}}TypeTransformer _instance;
}